﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using DGM.Objects.General;

namespace DGM.Util.Helpers.Bing
{
    public static class TranslateHelper
    {
	    public const string BingApiKey = "5565448f3b444d549e7e84eda85e36c8";

        public static string TranslateToEnglish(string text)
        {
					string q = string.Format("http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=Bearer {0}&text={1}&to={2}", BingApiKey, HttpUtility.UrlEncode(text), "en") ;

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(q);
            webRequest.Timeout = -1;
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

						using (var stream = webResponse.GetResponseStream())
						{


							var dcs = new DataContractSerializer(typeof (string));
							return (string) dcs.ReadObject(stream);
						}
        }
    }
}
